defmodule House.Web.PhotoView do
  use House.Web, :view

  def qiniu_file_and_url(upload) do
    ext = Path.extname(upload.filename)
    filename = rand_string() <> ext
    url = "http://" <> Application.fetch_env!(:qiniu, Qiniu)[:host] <> "/" <> filename
    {filename, url}
  end

  def rand_string(length \\ 24) do
    :crypto.strong_rand_bytes(length) |> Base.encode64 |> binary_part(0, length)
  end

  def kind_name(kind) do
    Enum.at(["室内", "小区", "其他"], kind - 1)
  end


end
